<%-- 
    Document   : postChat
    Created on : Apr 14, 2011, 10:55:17 AM
    Author     : Revolutors Styx
--%>

<%@page language = "java" import="chat.*" contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="bean.*" %>
<%@page import="java.util.*" %>
        <%
            ChatRoomList roomList = (ChatRoomList)application.getAttribute("roomList");
        
            String chatMessage = null;
            //get message from ChattoPost in user.jsp
            chatMessage = request.getParameter("message");
            /*
            *get the room selected
            */
            int chatRoomNumber;
            /*get room number from user session*/
            chatRoomNumber = Integer.parseInt(request.getParameter("roomId"));
            ChatRoom room = roomList.getRoomOfId(chatRoomNumber);
            //Chatter userWhoSendMessage = room.getChatter(request.getParameter("currentUser"));
            room.addMessage(new Message((session.getAttribute("username")).toString(),chatMessage,Calendar.getInstance().getTime().getTime()));
            out.println(chatMessage);
            out.println(room.getMessages()[0].getMessage());
            roomList.setRoom(chatRoomNumber, room);
            room = roomList.getRoomOfId(chatRoomNumber);
            out.println(room.getMessages()[0].getMessage());
            application.setAttribute("roomList", roomList);
        %>
